//Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.ComponentModel;
using System.Globalization;

namespace Microsoft.Office.OneNote
{
	/// <summary>
	/// Most hierarchy and page object nodes have their own ObjectId, which can be used to 
	/// uniquely identify the node across sessions.
	/// The object id consists of GUID, a version number, and the source data, e.g.:
	/// {12345678-1234-1234-1234-123456789012}{0}{B0}
	/// </summary>
	[Serializable]
    [TypeConverter(typeof(OneNoteObjectIdConverter))]
	public struct OneNoteObjectId : IEquatable<OneNoteObjectId>
	{
        private readonly String _value;

        private OneNoteObjectId(String value)
        {
            _value = value;
        }

        public bool Equals(OneNoteObjectId other)
        {
            return StringComparer.OrdinalIgnoreCase.Equals(_value, other._value);
        }

		public override bool Equals(object obj)
		{
            if (obj is OneNoteObjectId)
            {
                return Equals((OneNoteObjectId)(obj));
            }

            return false;
		}

		public override int GetHashCode()
		{
            if (_value == null)
            {
                return 0;
            }

            return _value.GetHashCode();
		}

        public override string ToString()
        {
            return _value;
        }

        public static bool operator ==(OneNoteObjectId left, OneNoteObjectId right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(OneNoteObjectId left, OneNoteObjectId right)
        {
            return !left.Equals(right);
        }

        public static OneNoteObjectId Parse(string value)
        {
            return new OneNoteObjectId(value);
        }

        public static bool TryParse(string value, out OneNoteObjectId result)
        {
            result = new OneNoteObjectId(value);
            return true;
        }

		public static readonly OneNoteObjectId Empty = new OneNoteObjectId();
    }
}